#ifndef myMessage_h__
#define myMessage_h__

#include "../inc/sky.h"
#include "./myHandler.h"
namespace Sky
{
	using namespace Sky;

	class myMsgMgr;

	class Msg : public Object
	{
		DECL_RTTI1(Msg,Object);
	public:
		typedef MsgStatus (Msg::*EventId)(myMsgMgr*,Msg*);
		Msg(EventId eid,Object* sender = vNull,Object* message = vNull):
			_event((Handler::EventId)eid),
			_sender(sender),
			_message(message)
			{
				xStaticAssert(sizeof(Handler::EventId) == sizeof(EventId),should_be_same_size);
			}
		
		template <typename cls>
		Bool isEvent(MsgStatus (cls::*eid)(myMsgMgr*,Msg*))
		{
			Handler::EventId e = (Handler::EventId)eid;
			return _event == e ? vTrue : vFalse;
		}

		Handler::EventId getEvent(){return _event;}

		ObjectPtr& getMessage(){return _message;}

		ObjectPtr& getSender(){return _sender;}

		MsgStatus invokeHandler(Handler* handler,myMsgMgr* mgr)
		{
			return (handler->*_event)(mgr,this);
		}
	protected:
		Handler::EventId  _event;
		ObjectPtr _sender;
		ObjectPtr _message;
		
	};
	typedef RefPtr<Msg> MessagePtr;
}
#endif // myEvent_h__
